const { createStore } = require("redux");

// 初始化的数据
const initialState = {
  "001": {
    id: "001",
    name: "zhangsan",
    age: 18,
    address: "北京市",
  },
};

// 定义一个 reducer 函数
function reducer(state = initialState, action) {
  switch (action.type) {
    case "ADD":
      return { ...state, [action.payload.id]: action.payload };
    case "DELETE":
      const newState = { ...state };
      delete newState[action.payload];
      return newState;
    default:
      return state;
  }
}

// 创建一个 Redux store
const store = createStore(reducer);

module.exports = store;
